package com.loong.game2048.dao;

import com.loong.game2048.module.Scope;
import com.loong.game2048.module.vo.ScopeVo;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author lyx
 * @date 2020/5/22 10:27
 */
@Mapper
public interface ScopeDao {


    @Select("select count(id) from scope where u_id = #{userId} ")
    Integer scopeHasExit(String userId);

    @Insert("insert into scope (u_id,game_id,scope) value (#{userId},#{gameId},#{scope})")
    Integer addScope(@Param("userId") String userId,@Param("gameId") Integer gameId,@Param("scope") Integer scope);

    @Update("update scope set scope=#{scope} where u_id=#{userId} and game_id = #{gameId}")
    Integer updateScope(@Param("userId") String userId,@Param("gameId") Integer gameId,@Param("scope") Integer scope);

    @Select("select * from scope where game_id = 1 order by scope desc limit 0,20")
    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "user",column = "u_id",one = @One(select = "com.loong.game2048.dao.UserDao.getUserMsgById")),
            @Result(property = "gameId",column = "game_id"),
            @Result(property = "scope",column = "scope")
    }
    )
    List<Scope> getAllSCope();

    @Select("select scope from scope where u_id = #{userId} and game_id = #{gameId} ")
    Integer getScope(@Param("userId") String userId,@Param("gameId") Integer gameId);

    @Select("select count(id) from scope where  game_id = #{gameId} and scope >#{scope}")
    Integer getScopeSort(@Param("gameId") Integer gameId,@Param("scope") Integer scope);
}
